import http from "./http.js";
const pk = "XEFBZ-BPWKL-4INPE-EKSQJ-6QLLS-SXBWU";
let item = {
	localmap: undefined,
	loadSsq: function() {
		return new Promise((resolve,reject) => {
			uni.request({
				url: "https://yl-1346967611.cos.ap-beijing.myqcloud.com/location/js_location.json",
				success: (data) => resolve(data),
				fail: (err) => reject(err)
			});
		});
	},
	loadLocation: function() {
		return new Promise((resolve,reject) => {
			uni.getFuzzyLocation({
				success: (data) => resolve(data),
				fail: (err) => reject(err)
			});
		});
	},
	jwdToLocation: function(latitude, longitude) {
		return new Promise((resolve,reject) => {
			uni.request({
				url: "https://apis.map.qq.com/ws/geocoder/v1/",
				data: {
					location: latitude + "," + longitude,
					key: pk
				},
				success: res => {
					if (res.data) {
						if (res.data.result) {
							resolve(res.data.result);
							return;
						}
					}
					
					reject(res)
				},
				fail: err => {
					reject(err)
				}
			});
		});
	},
	toCitySelector: function() {
		const key = pk; //使用在腾讯位置服务申请的key
		const referer = 'jl'; //调用插件的app的名称
		uni.navigateTo({
			url: `plugin://citySelector/index?key=${key}&referer=${referer}`,
		});
	},
	
};


item.loadSsq().then(data => {
	item.localmap = data.data;
});



export default item;
